<?php defined('BASEPATH') or exit('No direct script access allowed');

/**
 * 酒店模块
 *
 * Class Line_line_model
 */
class Hotel_hotel_model extends CI_Model
{

    private $sid ;
    private $hotel_info_table ;
    private $hotel_go_table ;
    public function __construct()
    {
        parent::__construct();
        $this->sid = $GLOBALS['sid'];
        $this->data = $GLOBALS['config'];
        $this->hotel_info_table = $this->db->dbprefix('hotel_info');
        $this->hotel_room = $this->db->dbprefix('hotel_room');
        $this->hotel_go_table = $this->db->dbprefix('hotel_go');
        $this->table_extend_product = $this->db->dbprefix('hotel_goods');
    }



  

    /**
     * 添加房间号
     * @param $array
     * @return true/false
     */
    public function _add_number($array)
    {
        $this->db->insert($this->hotel_room,$array);
        if($this->db->insert_id()) return true ;
        return false;
    }

    /**
     * 编辑房间号
     * @param $data
     * @return true/false
     */
    public function _edit_number($data,$where)
    {
        if(!empty($where))$this->db->where($where);
        return $this->db->update($this->hotel_room,$data);
        return false;
    }


    /**
     * 获取房间号单条数据
     * @param $array
     * @return true/false
     */
    public function _get_number_row($where = array(),$fields='*')
    {
        $this->db->select($fields);
        $this->db->from($this->hotel_room);
        if(!empty($where)) $this->db->where($where);
        $query = $this->db->get();
        $res = $query->row_array();
        return $res ;
    }


    /**
     *
     * 获取房间号总数量
     * @param array $where 查询条件
     */
    public function get_number_count($where= array())
    {
        if(!empty($where)) $this->db->where($where);
        $this->db->from($this->hotel_room);
        return $this->db->count_all_results() ;
    }


    /**
     * 获取所有房间列表
     * @param array $where 选择条件
     */

    public function get_number_list($where='',$page_size=20,$now_page=1)
    {
        $this->db->order_by('id','desc');
        $this->db->where($where);
        $query = $this->db->get($this->hotel_room,$page_size,($now_page-1)*$page_size);
        return $query->result_array();
    }

    /**
     * 获取所有房间号
     * @param array $where 选择条件
     */

    public function get_number_array($where='',$fields = '*')
    {
        $this->db->select($fields);
        $this->db->order_by('id','desc');
        $this->db->where($where);
        $query = $this->db->get($this->hotel_room);
        return $query->result_array();
    }

    /**
     *
     * 删除房间号
     * @param array $where 删除条件
     */

    public function _delete_number($where=array())
    {
        if(!empty($where)&&is_array($where))
        {
            return $this->db->delete($this->hotel_room,$where);
        }
        return false;
    }





    /**
     * 添加附加产品
     * @param $array
     * @return true/false
     */
    public function _add_extend_product($array)
    {
        $this->db->insert($this->table_extend_product,$array);
        if($this->db->insert_id()) return true ;
        return false;
    }

    /**
     * 编辑附加产品
     * @param $data
     * @return true/false
     */
    public function _edit_extend_product($data,$where)
    {
        if(!empty($where))$this->db->where($where);
        return $this->db->update($this->table_extend_product,$data);
        return false;
    }


    /**
     * 获取附加产品单条数据
     * @param $array
     * @return true/false
     */
    public function _get_extend_product_row($where = array())
    {
        $this->db->select('*');
        $this->db->from($this->table_extend_product);
        if(!empty($where)) $this->db->where($where);
        $query = $this->db->get();
        $res = $query->row_array();
        return $res ;
    }


    /**
     *
     * 获取附加产品总数量
     * @param array $where 查询条件
     */
    public function get_extend_product_count($where= array())
    {
        if(!empty($where)) $this->db->where($where);
        $this->db->from($this->table_extend_product);
        return $this->db->count_all_results() ;
    }


    /**
     * 获取所有附加产品
     * @param array $where 选择条件
     */

    public function get_extend_product_list($where='',$page_size=1000,$now_page=1)
    {
        $this->db->order_by('id','desc');
        $this->db->where($where);
        $query = $this->db->get($this->table_extend_product,$page_size,($now_page-1)*$page_size);
        return $query->result_array();
    }

    /**
     *
     * 删除附加产品
     * @param array $where 删除条件
     */

    public function _delete_extend_product($where=array())
    {
        if(!empty($where)&&is_array($where))
        {
            return $this->db->delete($this->table_extend_product,$where);
        }
        return false;
    }



}